package com.jzj.controller;


import com.jzj.pojo.Book;
import com.jzj.service.impl.BookService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;



@Controller
@ResponseBody
@RequestMapping("/book")
public class bookController {

    @Autowired
    private BookService bookService;



    @PostMapping ()
    public int addBook(@RequestBody Book book){
        int i = bookService.addBook(book);
        return 1;
    };


    @DeleteMapping("/{id}")
    public int delBook(@PathVariable int id){
        return bookService.delBook(id);
    };


    @PutMapping ()
    public int updateBook(@RequestBody Book book){
        int i = bookService.updateBook(book);
        return 1;
    };



    @GetMapping("/{id}")
    public Object selectBookbyId(@PathVariable int id){
        Object data= bookService.selectBookbyId(id);
        return data;
    }



    @GetMapping()
    public Object selectBook(@RequestParam(value = "bookName", required = false)String bookName){
        if(bookName!=null){
            System.out.println(1);
            Object data = bookService.selectOneBook(bookName);
            return data;
        }else {
            System.out.println(2);
            Object data = bookService.selectBook();
            return data;
        }

    };


}
